  //LTX_ParceLogFile
  //Tony Ringsmuth  2/21/02

C_LONGINT($TableNo;$Cnt;$pStart)

$EOL:=<>LT_EndOfLine

LT_vDocRef1:=Open document("";"";Read mode)
If (ok=1)

BB_Confirm ("Include Source data (non-hexed)?";"Yes";"No")
$bIncludeSrcData:=(ok=1)

LT_vDocRef2:=Create document("")
If (ok=1)
$ParceDocument:=document
BB_ThMessage ("Header")

$rSourceDocSize:=Get document size(LT_vDocRef1)

ARRAY TEXT(LT_aParceTableName;0)
$MisReadCount:=0
$SendDlmt:=$EOL+$EOL

If (True)
  //Send a measuring Line
SEND PACKET(LT_vDocRef2;"01 "+(" "*9))
For ($i;5;60;5)
SEND PACKET(LT_vDocRef2;String($i;"00")+(" "*13))
End for 
SEND PACKET(LT_vDocRef2;"65"+$EOL)
End if 

RECEIVE PACKET(LT_vDocRef1;$Pack;36)  //was 62
If (True)
  //04/06/09: Note: The header information is different in a log-backup file than a live log.
  //4D 2004: Log backup file, 1-4 = "CSFV"

If (Substring($Pack;1;4)="CSFV")
SET DOCUMENT POSITION(LT_vDocRef1;0)
RECEIVE PACKET(LT_vDocRef1;$Pack;<>LT_TagMarker)
SET DOCUMENT POSITION(LT_vDocRef1;-4;3)  //Back-up 4 characters, so that the next receive gets  the 4 character <>LT_TagMarker

LTX_ParceLogFileHdr (LT_vDocRef2;$Pack;1;"This is a v2004 Backup Log hdr (non-compressed)")
For ($i;5;Length($Pack);4)
LTX_ParceLogFileHdr (LT_vDocRef2;$Pack;$i;"Unknown")

End for 

Else 
LTX_ParceLogFileHdr (LT_vDocRef2;$Pack;1;"Sync Key?")
LTX_ParceLogFileHdr (LT_vDocRef2;$Pack;5;"Unused")
LTX_ParceLogFileHdr (LT_vDocRef2;$Pack;9;"Unused?")
LTX_ParceLogFileHdr (LT_vDocRef2;$Pack;13;"Seems to mark where the synchronization with this log file should END "+"(changes with each additional transaction) "+"note(10/1/2008): "+"Changed byte 16 enabled me to synch this with a datafile")
LTX_ParceLogFileHdr (LT_vDocRef2;$Pack;17;"Unused")
LTX_ParceLogFileHdr (LT_vDocRef2;$Pack;21;"Seems to mark where the synchronization with this log file should START "+"(does NOT"+" necessarily change with each additional transaction)")
LTX_ParceLogFileHdr (LT_vDocRef2;$Pack;25;"Associated Backup Number")
LTX_ParceLogFileHdr (LT_vDocRef2;$Pack;29;"Signature that links to Datafile: "+"Related to bytes 8-11 of File Information Table of the Data file")
LTX_ParceLogFileHdr (LT_vDocRef2;$Pack;33;"Log file size (minus 24)")
End if 
SEND PACKET(LT_vDocRef2;$EOL)
Else 

SEND PACKET(LT_vDocRef2;LTX_CharsToHex ($Pack)+$EOL+$EOL)
If ($bIncludeSrcData)
SEND PACKET(LT_vDocRef2;$Pack+$EOL+$EOL)
End if 
SEND PACKET(LT_vDocRef2;$EOL+$EOL)
End if 
BB_ThInit ($rSourceDocSize;"Parcing Log File")
BB_EventMonitorStart 

$Cnt:=0
Repeat 
$Cnt:=$Cnt+1
$currentDocPosition:=Get document position(LT_vDocRef1)
If ($Cnt%10=0)
BB_ThUpdate ($currentDocPosition;String($Cnt))
End if 
RECEIVE PACKET(LT_vDocRef1;$Pack;16)
If (Length($Pack)<16)
$ok:=0
Else 
$ok:=ok
End if 
$pStart:=BB_PositionInText (<>LT_TagMarker;Substring($Pack;1;4))

If ($pStart=1)  //04 04 99 99: Primary Prefix

$ActionType:=Character code($Pack[[9]])
$iFind:=Find in array(<>LT_aAction_ID;$ActionType)
$ActionShortName:=""
If ($iFind>-1)
$ActionShortName:=<>LT_aAction_Short{$iFind}
Else 
$ActionShortName:="(#"+String($ActionType)+")"
End if 
$Send1:="Address: "+String($currentDocPosition)+": "+$ActionShortName+Char(9)

Case of 
: (($ActionType=1) | ($ActionType=3))  //Add, Mod records.  Variable size data following
RECEIVE PACKET(LT_vDocRef1;$Pack2;8)
$Pack:=$Pack+$Pack2

$TableNo:=Character code($Pack[[19]])*256+Character code($Pack[[20]])
If (($TableNo>0) & ($TableNo<=Size of array(LT_aParceTableName)))
$TableName:="["+LT_aParceTableName{$TableNo}+"]"
Else 
$TableName:="["+String($TableNo)+"]"
End if 

SEND PACKET(LT_vDocRef2;$Send1+$TableName+$EOL)
SEND PACKET(LT_vDocRef2;LTX_CharsToHex (Substring($Pack;1;16))+"."+LTX_CharsToHex (Substring($Pack;17)))

$TotalRecSize:=LT_WordToLongint (Substring($Pack;21;4);Macintosh byte ordering)

$RecPack:=""
If ($TotalRecSize<8000)
RECEIVE PACKET(LT_vDocRef1;$RecPack;$TotalRecSize)
SEND PACKET(LT_vDocRef2;LTX_CharsToHex ($RecPack)+$SendDlmt)
Else 
$RemainToReceive:=$TotalRecSize
Repeat 
RECEIVE PACKET(LT_vDocRef1;$RecPack;8000)
SEND PACKET(LT_vDocRef2;LTX_CharsToHex ($RecPack))
$RemainToReceive:=$RemainToReceive-8000
Until ($RemainToReceive<8000)
If ($RemainToReceive>0)
RECEIVE PACKET(LT_vDocRef1;$RecPack;$RemainToReceive)
SEND PACKET(LT_vDocRef2;LTX_CharsToHex ($RecPack)+$SendDlmt)
End if 
End if 

: ($ActionType=2)  //delete 
SEND PACKET(LT_vDocRef2;$Send1+LTX_CharsToHex ($Pack)+".")
RECEIVE PACKET(LT_vDocRef1;$Pack;8)
SEND PACKET(LT_vDocRef2;LTX_CharsToHex ($Pack)+$SendDlmt)

: (($ActionType=4) | ($ActionType=5) | ($ActionType=6))  //Transaction Start, Validate, Cancel
SEND PACKET(LT_vDocRef2;$Send1+LTX_CharsToHex ($Pack)+".")
RECEIVE PACKET(LT_vDocRef1;$Pack;10)
SEND PACKET(LT_vDocRef2;LTX_CharsToHex ($Pack)+$SendDlmt)

: ($ActionType=7)  //Table Description Following 
SEND PACKET(LT_vDocRef2;$Send1+LTX_CharsToHex ($Pack)+".")
RECEIVE PACKET(LT_vDocRef1;$Pack;8)
SEND PACKET(LT_vDocRef2;LTX_CharsToHex ($Pack)+$SendDlmt)

LTX_ParceLogFile_TableHeaders 
BB_ThInit ($rSourceDocSize;"Parcing Log File")
BB_ThUpdate (Get document position(LT_vDocRef1);String($Cnt))

: (($ActionType=8) | ($ActionType=9) | ($ActionType=10))  //Quit 4D Server, Start Flush Buffer, End Flush Buffer
SEND PACKET(LT_vDocRef2;$Send1+LTX_CharsToHex ($Pack)+".")
RECEIVE PACKET(LT_vDocRef1;$Pack;8)
SEND PACKET(LT_vDocRef2;LTX_CharsToHex ($Pack)+$SendDlmt)

Else 
SEND PACKET(LT_vDocRef2;$Send1+LTX_CharsToHex ($Pack)+".")
  //BEEP
TRACE
End case 

Else 

$MisReadCount:=$MisReadCount+1

SET DOCUMENT POSITION(LT_vDocRef1;-Length($Pack);3)  //Relative to current position.
RECEIVE PACKET(LT_vDocRef1;$Pack;8192+3)

$pStart:=BB_PositionInText (<>LT_TagMarker;$Pack)
If ($pStart>0)
$PackSend:=Substring($Pack;1;$pStart-1)
SEND PACKET(LT_vDocRef2;String($currentDocPosition)+": "+LTX_CharsToHex ($PackSend)+$EOL+$EOL)
If ($bIncludeSrcData)
SEND PACKET(LT_vDocRef2;$PackSend+$EOL+$EOL)
End if 
SET DOCUMENT POSITION(LT_vDocRef1;$pStart-Length($Pack)-1;3)  //Relative to current position.
Else 
$PackSend:=Substring($Pack;1;Length($Pack)-3)
SEND PACKET(LT_vDocRef2;String($currentDocPosition)+": "+LTX_CharsToHex ($PackSend))
If ($bIncludeSrcData)
SEND PACKET(LT_vDocRef2;$PackSend)
End if 
SET DOCUMENT POSITION(LT_vDocRef1;-3;3)
  //Backup 3 characters to ensure that we don't read across the delimiter
  //  between reads.

End if 


End if 

Until (($ok=0) | (Not(BB_EventContinue )))
BB_ThClose 
BB_EventMonitorStop 

CLOSE DOCUMENT(LT_vDocRef2)
SHOW ON DISK($ParceDocument)
End if 
CLOSE DOCUMENT(LT_vDocRef1)


End if 
  //